一、上传解压后的Hbase文件。
二、配置:
1、.bash_profile文件:
export HBASE_HOME=/home/kituser/bigdata/hbase-0.94.6-cdh4.5.0
export CLASSPATH=$CLASSPATH:$HBASE_HOME/lib
export PATH=$PATH:$HBASE_HOME/bin:$HBASE_HOME/sbin
2、regionservers文件
kit-b6
kit-b7
3、hbase-env.sh文件
export JAVA_HOME=/usr/java/jdk1.7.0_45
export HBASE_MANAGES_ZK=true
4、hbase-site.xml文件
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://kit-b5:8020/hbase</value>
</property><property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property><property>
<name>hbase.master</name>
<value>kit-b5:60000</value>
</property><property>
<name>hbase.zookeeper.quorum</name>
<value>kit-b5,kit-b6,kit-b7</value>
</property><property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property><property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/data/kituser_hadoop_tmp/zookeeper</value>
<description>Property fromZooKeeper's config zoo.cfg. The directory where the snapshot isstored.
</description>
</property><property>
<name>hbase.regionserver.lease.period</name>
<value>120000</value>
</property><property>
<name>hbase.rpc.timeout</name>
<value>120000</value>
</property></configuration>
三、验证Hbase安装
1、启动/停止服务
start-hbase.sh
stop-hbase.sh
hbase shell //启动shell
2、web界面查看:
3、命令:
创建表:create 'member','member_id','address','info'
显示表:list
显示表描述:describe 'member'
禁用表:disable 'member'
删除一个列族:alter'member',{NAME=>'member_id',METHOD=>'delete'}
启用表:enable 'member'
删除表:drop 'member'
查询表是否存在:exists 'member'
判断表是否enabled: is_enabled 'member'
判断表是否disable:is_disabled 'member'
插入记录:
put'member','scutshuxue','info:age','24' put'member','scutshuxue','info:birthday','1987-06-17' put'member','scutshuxue','info:company','alibaba' put'member','scutshuxue','address:contry','china' put'member','scutshuxue','address:province','zhejiang' put'member','scutshuxue','address:city','hangzhou' put'member','xiaofeng','info:birthday','1987-4-17' put'member','xiaofeng','info:favorite','movie' put'member','xiaofeng','info:company','alibaba' put'member','xiaofeng','address:contry','china' put'member','xiaofeng','address:province','guangdong' put'member','xiaofeng','address:city','jieyang' put'member','xiaofeng','address:town','xianqiao'获取一个id的所有数据:get 'member','scutshuxue'
获取一个id,一个列族的所有数据:get 'member','scutshuxue','info'
获取一个id,一个列族中一个列的所有数据:get 'member','scutshuxue','info:age'
修改scutshuxue的年龄为99:put 'member','scutshuxue','info:age' ,'99'
通过timestamp来获取两个版本的数据:
- get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586238965}
- get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586571843}
全表扫描:scan 'member'
删除id为temp的值的'info:age'字段:delete 'member','temp','info:age'
删除整行:deleteall 'member','xiaofeng'
查询表中有多少行:count 'member'
给‘xiaofeng’这个id增加'info:age'字段,并使用counter实现递增:
- incr 'member','xiaofeng','info:age' COUNTER VALUE = 1
- incr 'member','xiaofeng','info:age' COUNTER VALUE = 2
将整张表清空:truncate 'member'
四、错误及解决:
1、启动时报Name or service not knownstname错误
解决:记不清了,好像是因为regionservers文件GBK、UTF-8编码不对的问题造成的,应该用UTF-8。
2、HMaster启动后,一会就停止,日志中报如下错误:
2014-06-19 16:44:42,296 INFO org.apache.zookeeper.ClientCnxn: Opening socket connection to server kit-b1/172.16.19.151:2181. Will not attempt to authenticate using SASL (unknown error)2014-06-19 16:44:42,296 WARN org.apache.zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: 拒绝连接at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)2014-06-19 16:44:42,397 INFO org.apache.zookeeper.ClientCnxn: Opening socket connection to server kit-b2/172.16.19.152:2181. Will not attempt to authenticate using SASL (unknown error)2014-06-19 16:44:42,397 WARN org.apache.zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: 拒绝连接at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)2014-06-19 16:44:42,498 INFO org.apache.zookeeper.ClientCnxn: Opening socket connection to server kit-b3/172.16.19.153:2181. Will not attempt to authenticate using SASL (unknown error)2014-06-19 16:44:42,499 WARN org.apache.zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: 拒绝连接at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:350)at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1068)
解决:两种方法:1、运行启动两次start-hbase.sh;2、启动一次start-hbase.sh后,到kit-b2、 kit-b3上手动启动localregionservers.sh命令。我是用第1种生效的。第2种是测试时使用的。